#include cooker/cooking.mk
Awk0=gawk
Tmp=$(HOME)/tmp
Dirs=$(Tmp)
Profile=$(Tmp)/acbprof.out
Vars=$(Tmp)/acbvars.out
Revision=$(shell svn info | $(Awk0) '/Revision/ {print $$2}')
Cookbook=../src/release/older/cookbook$(Revision).awk
CookbookLatest=../src/release/cookbook.awk
Pre:= $(shell ls ../content/*.awk)
Demos:=$(shell $(Awk0) -f cooker/demos.awk ../content/*.awk) 
Rules:=$(shell $(Awk0) -F: '$$1 ~ /^[A-Z]/ {print $$1}' Makefile)
Ready=$(subst content,src/test,$(Pre))
Spy= pgawk --profile=$(Profile) --dump-variables=$(Vars)  -f $(subst .awk ,.awk -f ,$(Ready))
Run= gawk  -f $(subst .awk ,.awk -f ,$(Ready))
Dump = if cat $(Vars) | egrep -v '^[A-Z]+:' ; then true; else true; fi;
I    = printf "\n---| $(This) |----------------------------\n\n"
a    = $(Run)  --source 'BEGIN {#
z    = ; exit;}'
A    = $(Spy)  --source 'BEGIN {#
Z    = ; exit;}'

install : installDirs readies

installDirs :
	@$(foreach d, $(Dirs),\
		if [ ! -d "$d" ]; then echo "making $d"; mkdir -p $d; fi; )

readies : $(Ready)

one : readies
	@$A $(This)() $Z

../src/test/%.awk : ../content/%.awk
	@echo "ready $@" >&2
	@$(Awk0) -f cooker/ready.awk $< > $@

dump : readies
		@$A print "Acb" $Z; $(Dump)

cookbook : readies
	@cat ../etc/header.txt  > $(CookbookLatest)
	@printf "# Revision: $(Revision)\n\n" >> $(CookbookLatest)
	@cat ../COPYRIGHT.txt >> $(CookbookLatest)
	@$(Awk0) -f cooker/cooking.awk test/*.awk  >> $(CookbookLatest)
	@cp $(CookbookLatest) $(Cookbook)
	@svn -q add $(Cookbook)
